package core;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.geom.Point2D;

/**
 * @author Robbie Groenewoudt
 *
 */
public class Explosion implements Drawable {
	
	private int explosionFrameNumber = 0;
	private int tillExplosionFrameNumber = 15;
	private boolean stay = false;
	
	private Point position;
	
	public Explosion( Point2D.Double pos, int size, boolean stay )
	{
		this.position = new Point( (int)pos.x, (int)pos.y);
		this.stay = stay;
		this.tillExplosionFrameNumber = (int)(size * Model.timerInterval * 10);
	}
	
	public Explosion( Point2D.Double pos, int size )
	{
		this( pos, size, false );
	}

	public void draw(Graphics g, Rectangle area, Component c) {
        // Draw an "explosion" that grows in size as the number of
        // frames since the start of the explosion increases.
		if ( explosionFrameNumber < tillExplosionFrameNumber )
			explosionFrameNumber++;
		
	    g.setColor(Color.YELLOW);
	    g.fillOval( position.x - 4*explosionFrameNumber,
	    		position.y - 2*explosionFrameNumber,
	          8*explosionFrameNumber,
	          4*explosionFrameNumber);
	    g.setColor(Color.RED);
	    g.fillOval(position.x - 2*explosionFrameNumber,
	    		position.y - explosionFrameNumber/2,
	          4*explosionFrameNumber,
	          explosionFrameNumber);
	}
	
	/**
	 * Is explosie klaar met exploderen?
	 * @return boolean
	 */
	public boolean isDone() {
		return !stay && explosionFrameNumber >= tillExplosionFrameNumber;
	}

	/**
	 * @return the position
	 */
	public Point getPosition() {
		return position;
	}

}
